package Matrix;

public class Matrix {

	//input output
	public static double[][] get_input(double[][] data , int input_size){
		int col = data.length;
		int row = input_size;
		double[][] result = new double[col][row];
		
		for(int i = 0 ; i < col ; i++){
			for(int j = 0 ; j < row ; j++){
				result[i][j] = data[i][j];
			}
		}
		
		return result;
	}
	
	public static double[][] get_output(double[][] data , int output_size){
		int col = data.length;
		int row = output_size;
		int trow = data[0].length;
		
		double[][] result = new double[col][row];
		
		for(int i = 0 ; i < col ; i++){
			for(int j = 0 ; j < row ; j++){
				result[i][j] = data[i][trow-row+j];
			}
		}
		
		return result;
	}
	
	//train test
	public static double[][] get_train(double[][] data){
		int col = data.length;
		int row = data[0].length;
		
		double[][] result = new double[col/2][row];
		int rcol = 0;
		
		for(int i = 0 ; i < col ; i++){
			
			if( (i % 2) == 0){
				result[rcol] = data[i];
				rcol++;
			}
		}
	
		return result;
	}

	public static double[][] get_test(double[][] data){
		int col = data.length;
		int row = data[0].length;
		
		double[][] result = new double[col/2][row];
		int rcol = 0;
		
		for(int i = 0 ; i < col ; i++){
			
			if( (i % 2) != 0){
				result[rcol] = data[i];
				rcol++;
			}
		}
	
		return result;
	}
	
	//matrix
	public static double[][] copy(double[][] data){
		
		int row = data[0].length;
		int col = data.length;

		double array[][] = new double[col][row]; 
				
		for(int i = 0 ; i < col ; i++){
			for(int j = 0 ; j < row ; j++){
				array[i][j] = data[i][j];
			}
		}
		
		return array;
	}

	public static double[] copy(double[] data){
		
		int row = data.length;

		double array[] = new double[row]; 
		for(int i = 0 ; i < row ; i++){
			array[i] = data[i];
		}
		
		return array;
	}

	public static double[][] extend(double[] data){
		int col = 1;
		int row = data.length;
		double array[][] = new double[col][row];
		
		for(int i = 0 ; i < col ; i++){
			array[i] = data;
		}
		
		return array;
	}

	public static double[] sort(double[] data){
		int row = data.length;
		double array[] = data;
		double tmp;
		
		for(int i = 0 ; i < row-1 ; i++){
			for(int j = i+1 ; j < row ; j++){
				if( array[i] > array[j] ){
					tmp = array[i];
					array[i] = array[j];
					array[j] = tmp;
				}
			}
		}
		
		return array;
	}

	
}